<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<link rel="stylesheet" type="text/css" href="main.css" />
<title>My Account</title>
<script type="text/javascript">
function returnBook(i)
{
	var xmlHttp = new XMLHttpRequest();
	xmlHttp.open("GET", "issue?action=return&bookId="+i, false);
	xmlHttp.send();
	var text = xmlHttp.responseText;
	document.getElementById("ajax"+i).innerHTML=text;
}
</script>
</head>
<body>
	<%@include file="header.jsp"%>
	<article> 
	<s:set name="jissues" value="issues" scope="request" /> 
	<br />
	<c:choose>
		<c:when test="${empty jissues }">
		There are no open borrowings for you!<br />
		</c:when>
		<c:otherwise>
			Your borrowings!
			<table>
				<tr>
					<th>Sl No</th>
					<th>Book Name</th>
					<th>Due Date</th>
					<th>Issue Date</th>
					<th>Comments</th>
					<th>s</th>
				</tr>
				<c:forEach var="issue" items="${jissues}" varStatus="status">
					<tr>
						<td>${status.count}</td>
						<td>${issue.bookName}</td>
						<td>${issue.dueDate}</td>
						<td>${issue.issueDate}</td>
						<td><button type="button"
								onclick="returnBook(${issue.bookId})">Return</button></td>
						<td><p id="ajax${issue.bookId}"></p></td>
					</tr>
				</c:forEach>
			</table>
		</c:otherwise>
	</c:choose> 
	<s:set name="reserves" value="reserves" scope="request" />
	<c:choose>
		<c:when test="${empty reserves}">
			There are no book requests for you!
		</c:when>
		<c:otherwise>
			Your Book Requests!
			<table>
				<tr>
					<th>No</th>
					<th>Book Name</th>
					<th>Request Date</th>
					<th>Remarks</th>
				</tr>
				<c:forEach var="reserve" items="${reserves}" varStatus="status">
				<tr>
					<td>${status.count }</td>
					<td>${reserve.bookName }</td>
					<td>${reserve.reserveDate }</td>
					<td></td>
				</tr>
				</c:forEach>
			</table>
		</c:otherwise>
	</c:choose>
	</article>
	<%@include file="footer.jsp"%>
</body>
</html>